home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions Synapse component
-
- #include "NSDLL.h"
-
- /***********************************/
- /* Forward activation of component */
- __declspec(dllexport) void performSynapse(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to the input layer of processing elements (PEs)
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- NSFloat *output, // Pointer to the output layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols // Number of columns of PEs in the output layer
- )
- {
- BOOL subInput = getBoolParameter(instance, 1, 1);
- int i,
- inCount = subInput? getIntParameter(instance, 3, 1): inRows*inCols,
- outCount = !subInput? getIntParameter(instance, 3, 1): outRows*outCols,
- start = getIntParameter(instance, 2, 1),
- count = inCount<outCount? inCount: outCount;
-
- if (subInput)
- for (i=0; i<count; i++)
- output[i] += input[i+start];
- else
- for (i=0; i<count; i++)
- output[i+start] += input[i];
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- __declspec(dllexport) DLLData *allocSynapse(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols // Number of columns of PEs in the output layer
- )
- {
- BOOL subInput;
- int maxLength, start, length;
- DLLData *instance = allocDLLInstance(oldInstance);
- setParameterName(instance, 1, 1, "Input", TRUE);
- setBoolParameter(instance, 1, 1, TRUE, FALSE);
- setParameterName(instance, 2, 1, "Start", TRUE);
- setIntParameter(instance, 2, 1, 0, FALSE);
- setParameterName(instance, 3, 1, "Length", TRUE);
- setIntParameter(instance, 3, 1, 1, FALSE);
- subInput = getBoolParameter(instance, 1, 1);
- maxLength = subInput? inRows*inCols: outRows*outCols;
- start = getIntParameter(instance, 2, 1);
- if (inRows && inCols && outRows && outCols) {
- if (start >= maxLength)
- start = maxLength-1;
- length = getIntParameter(instance, 3, 1);
- if (start+length > maxLength)
- length = maxLength-start;
- if (!subInput)
- if (length > inRows*inCols)
- length = inRows*inCols;
- } else
- start = length = 0;
- setBoolParameter(instance, 1, 1, subInput, TRUE);
- setIntParameter(instance, 2, 1, start, TRUE);
- setIntParameter(instance, 3, 1, length, TRUE);
- return instance;
- }
-
- __declspec(dllexport) void freeSynapse(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
-